package com.dongqi.myblog.service.impl;

import com.dongqi.myblog.po.TUser;
import com.dongqi.myblog.mapper.TUserMapper;
import com.dongqi.myblog.service.OssService;
import com.dongqi.myblog.service.TUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dongqi.myblog.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dongqi
 * @since 2020-08-03
 */
@Service
public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser> implements TUserService {

    @Autowired
    private OssService ossService;

    /**
     * 更改admin个人信息
     */
    @Override
    public boolean saveUser(Long id, TUser user, MultipartFile file) {
        if (!file.isEmpty()){
            String url = ossService.uploadFileAvatar(file);
            user.setAvatar(url);
        }
        user.setPassword(MD5Utils.code(user.getPassword().trim()));
        user.setId(id);
        return this.updateById(user);
    }

}
